package cn.detu.ln.controller;

import cn.detu.ln.entity.Grade;
import cn.detu.ln.service.GradeService;
import cn.detu.ln.utils.PageUtil;
import cn.detu.ln.utils.RestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("grade")
public class GradeController {
    @Autowired
    private GradeService gradeService;
    // GET请求获取用户列表数据
    // localhost:1314/user/selectAll
    @GetMapping("{url}")
    public RestUtil userGet(@PathVariable String url, Grade grade, PageUtil pageUtil, String search){
        switch (url){
            case "selectAll": return gradeService.selectAll();
            case "gradeDelete":return gradeService.gradeDelete(grade.getGradeId());
            // 所有成绩   按课程名称模糊查询
            case "queryGradeByPage":return gradeService.queryGradeByPage(pageUtil.getCurrent(),pageUtil.getRows(),
                    grade.getStuNum(),search);
            // 按学号模糊查询成绩
            case "queryGradeByStuNumPage":return gradeService.queryGradeByStuNumPage(pageUtil.getCurrent(),pageUtil.getRows(),
                    search);
            // 按学年查询成绩
            case "queryGradeByGradeYearPage":return gradeService.queryGradeByGradeYearPage(pageUtil.getCurrent(),
                    pageUtil.getRows(),grade.getStuNum(), search);
            // 按课程性质模糊查询
            case "queryGradeByCouNaturePage":return gradeService.queryGradeByCouNaturePage(pageUtil.getCurrent(),pageUtil.getRows(),
                    grade.getStuNum(),search);
            // 教师按课程名称查看学生成绩
            case "queryGradeByTeaCourse":return gradeService.queryGradeByTeaCourse(pageUtil.getCurrent(),pageUtil.getRows(), search);
            // 教师按课程名称 + 学号查询某个学生的成绩
            case "gradeCourseStu":return  gradeService.gradeCourseStu(pageUtil.getCurrent(),pageUtil.getRows(),search,grade.getStuNum());
            // 教师查看是否有成绩
            case "judgeGradeByCouId":return gradeService.judgeGradeByCouId(grade.getCouId());
            // 管理员依据课程名称查看成绩
            case "selectGradeCouNameByAdmin":return gradeService.selectGradeCouNameByAdmin(pageUtil.getCurrent(),
                    pageUtil.getRows(),search);
            // 管理员依据课程性质查看成绩
            case "selectGradeCouNatureByAdmin":return gradeService.selectGradeCouNatureByAdmin(pageUtil.getCurrent(),
                    pageUtil.getRows(),search);

        }

        return null;
    }
    @PostMapping("{url}")
    public RestUtil userPost(@PathVariable String url, Grade grade){
        switch (url){
            case "gradeUpdate":return gradeService.gradeUpdate(grade);
            case "gradeInsert":return gradeService.gradeInsert(grade);
        }
        return null;
    }
}
